

#include"../include/p.h"
#include<stdio.h>
int tcp_newcom(int tcp_socket)
{
	char buf[200]={0};
//	char cmd[200]={0};
//	char filename[100]={0};
	while(1)	
	{
		memset(buf,'\0',sizeof(buf));
		fgets(buf,sizeof(buf),stdin);
		if(strncmp(buf,"register",8)==0)
		{
			printf("开始注册\n");
		}
		
		else if(strncasecmp(buf,"login",5)==0)
		{
			printf("开始登录\n");
		}
	//这里系统调用函数send，和write类似	
		send(tcp_socket,buf,strlen(buf),0);	
		if(strncmp(buf,"quit",4)==0)		
		{
			printf("已退出newcom\n");
			return 2;
		}
		//清空buf;接收新消息；
		memset(buf,0,sizeof(buf));
		recv(tcp_socket,buf,sizeof(buf),0);
		printf("\n");
		
		printf("%s\n",buf);
		
		if(strncmp(buf,"注册成功",4)==0)
		{
			printf("您已成功登录！\n");
			break;
		}
		if(strncmp(buf,"登录失败",4)==0)
		{
			printf("登录失败\n");
			return -1;
		}
		if(strncmp(buf,"注册失败",4)==0)
		{
			printf("注册失败\n");
			return -1;
		}
		//printf("do work成功\n");
		
	}
	return 0;
}
